//
//  HomeMenusCollectionViewCell.m
//  YYZB
//
//  Created by 顾悦 on 16/8/8.
//
//

#import "HomeBizMenusCollectionViewCell.h"

#import "HomeBizMenuCollectionViewCell.h"

#import "UIColor+Hex.h"
#import "UIImageView+OnlineImage.h"
#import "HomeBizMenusCell.h"

@interface HomeBizMenusCollectionViewCell () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@end

@implementation HomeBizMenusCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.scrollEnabled = NO;
    [self.collectionView registerClass:[HomeBizMenusCell class] forCellWithReuseIdentifier:@"HomeBizMenusCell"];
//    [self.collectionView registerNib:[UINib nibWithNibName:@"HomeBizMenuRegularCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBizMenuRegularCollectionViewCell"];
//    [self.collectionView registerNib:[UINib nibWithNibName:@"HomeBizMenuCompactCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBizMenuCompactCollectionViewCell"];
}

- (void)setItems:(NSArray<BizMenu *> *)items {
    _items = items;
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.collectionView reloadData];
    });
}

- (CGFloat)estimateHeight {
    if (_estimateHeight <= 0) {
        _estimateHeight = 90;
    }
    
    return _estimateHeight;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.items.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    HomeBizMenusCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeBizMenusCell" forIndexPath:indexPath];
   
    [cell bindData:self.items[indexPath.item]];
//    HomeBizMenuCollectionViewCell *cell;
//    if (indexPath.item == 0) {
//        cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeBizMenuRegularCollectionViewCell" forIndexPath:indexPath];
//    } else {
//        cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeBizMenuCompactCollectionViewCell" forIndexPath:indexPath];
//    }
//    BizMenu *b = self.items[indexPath.item];
//    cell.backgroundImageView.hidden = [b.ConfigType integerValue] != 2;
//    [cell.backgroundImageView setOnlineImage:b.FullImgPath];
//    [cell.iconImageView setOnlineImage:b.LogoImgPath];
//    cell.backgroundColor = [UIColor colorWithHex:b.Background];
//    cell.titleLabel.text = b.ModuleName;
//    NSArray *subTitles = [b.Subheading componentsSeparatedByString:@"|"];
//    cell.subTitle0Label.text = subTitles.count > 0 ? subTitles[0] : @"";
//    cell.subTitle1Label.text = subTitles.count > 1 ? subTitles[1] : @"";
//    cell.subTitle2Label.text = subTitles.count > 2 ? subTitles[2] : @"";
//    cell.subTitle3Label.text = subTitles.count > 3 ? subTitles[3] : @"";
    
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGSize boundsSize = collectionView.bounds.size;
    
    return CGSizeMake(boundsSize.width - 20, 120);
  
}

@end
